package com.liu.eduService.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liu.R;
import com.liu.eduService.client.OrderClient;
import com.liu.eduService.entity.EduCourse;
import com.liu.eduService.entity.EduTeacher;
import com.liu.eduService.entity.FrontVo.FrontCourseAllInfoVo;
import com.liu.eduService.entity.FrontVo.FrontCourseQuery;
import com.liu.eduService.entity.chapter.ChapterVo;
import com.liu.eduService.service.EduChapterService;
import com.liu.eduService.service.EduCourseService;
import com.liu.eduService.service.EduTeacherService;
import com.liu.serviceBase.exception.MyException;
import com.liu.utils.JwtUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * **************
 * 项目名称: testgulili <br/>
 * 文件名称:  <br/>
 * 文件描述: 这里添加您的类文件描述，说明当前文件要包含的功能。 <br/>
 * 文件创建：刘世锦 <br/>
 * 创建时间: 2022/2/8 <br/>
 *
 * @version v1.0 <br/>
 * @update [序号][日期YYYY-MM-DD][更改人姓名][变更描述]<br/>
 * *************
 */
@RestController
@CrossOrigin
@RequestMapping("/eduService/coursefront")
public class FrontCourseController {

    @Autowired
    private EduCourseService eduCourseService;

    @Autowired
    private EduChapterService chapterService;

    @Autowired
    private OrderClient orderClient;

    @PostMapping("getCoursePageInfo/{page}/{limit}")
    public R  getCoursePageInfo(@PathVariable Long page, @PathVariable Long limit,
//                       条件可能没有
             @RequestBody(required = false) FrontCourseQuery courseQuery ){
        Page<EduCourse> CoursePage = new Page<>(page,limit);

        Map<String,Object> map  = eduCourseService.queryFrontCourse(CoursePage,courseQuery);
        return R.ok().data(map);
    }

        /**
            * 方法名称： <br/>
            * 功能描述:  <br/>
            * 方法参数：<br/>
            * 结果返回： <br/>
            * 创建作者：刘世锦 <br/>
            * 创建时间: 2022-02-09 12:21<br/>
            * 更新作者：2022/2/9<br/>
            * 更新信息: [序号][日期YYYY-MM-DD] [更改人姓名][变更描述] <br/>
            */
    @GetMapping("getCourseInfoById/{courseId}")
    public R getCourseInfoById(@PathVariable String courseId, HttpServletRequest request){

        if (ObjectUtils.isEmpty(request)){
            throw new MyException(20001,"FrontCourseController的getCourseInfoById(),request为空，用户未登录！");
        }
        FrontCourseAllInfoVo courseAllInfo = eduCourseService.getCourseAllInfo(courseId);

        //        2、其小节列表
        List<ChapterVo> chapterVoList = chapterService.findChapterBycourseId(courseId);
        String memberId = JwtUtils.getMemberIdByJwtToken(request);
        Boolean orderStatus = orderClient.getOrderStatus(memberId, courseId);
        return R.ok()
                    .data("courseAllInfo",courseAllInfo)
                    .data("chapterVoList",chapterVoList)
                    .data("orderStatus",orderStatus);

    }





}
